package com.ug.web.task;

import com.ug.common.core.domain.entity.SysUser;
import com.ug.system.domain.SysOperLog;
import com.ug.system.mapper.SysOperLogMapper;
import com.ug.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ScheduledTasks {

    @Autowired
    private SysOperLogMapper  opeLogMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    final static int COUNT_MAX = 1000;
    @Scheduled(cron = "0 0 * * * ?")
    public void dailyTask() {
        List<String> count = opeLogMapper.selectPersonalCount(COUNT_MAX);
        for(String i:count){
            Long id = Long.valueOf(i);
            SysUser user = new SysUser();
            user.setUserId(id);
            user.setStatus("1");
            sysUserMapper.updateUser(user);
        }
    }

    @Scheduled(cron = "0 0 0 30 * ?")
    public void monthlyTask(){
        List<SysOperLog> list = opeLogMapper.selectOperLogList(new SysOperLog());
        opeLogMapper.insert(list);
        Long[] ll = new Long[list.size()];
        for(int i=0;i<list.size();i++){
            ll[i] = list.get(i).getOperId();
        }
        opeLogMapper.deleteOperLogByIds(ll);
    }

}
